package cn.lili.modules.promotion.mapper;

import cn.lili.modules.promotion.entity.dos.SeckillApply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 秒杀活动申请数据处理层
 *
 * @author Chopper
 * @since 2020/8/21
 */
public interface SeckillApplyMapper extends BaseMapper<SeckillApply> {

    @Select("select sa.*" +
            "from li_seckill_apply sa " +
            "inner join (SELECT goods_id, MIN(price) AS min_price FROM li_seckill_apply " +
            "where seckill_id = #{seckillId} and delete_flag = 0 group by goods_id) t2 " +
            "ON sa.goods_id = t2.goods_id AND sa.price = t2.min_price " +
            "where sa.seckill_id = #{seckillId} and sa.delete_flag = 0 group by sa.goods_id")
    List<SeckillApply> getSeckillList (@Param("seckillId")String seckillId);
}